package com.xb.loan.admin.util;

import com.xb.loan.log.exception.BizException;
import com.xb.loan.util.strategy.TableNoAllocatorFactory;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 *
 * 项目名称 : oss-center
 * 创建日期 : 2015年12月4日
 * 类  描  述 : 抽象的工具服务
 */
public abstract class AbstractUtilService{

	/*
	 * redis 时间间隔
	 */
	public final static Map<String,String> timeMap = new LinkedHashMap<String,String>();
	static{
		timeMap.put("5", "5");
		timeMap.put("10", "10");
		timeMap.put("15", "15");
		timeMap.put("20", "20");
	}
	/*
	 * redis 监控对象
	 */
	public final static Map<String,String> monitoringMap = new LinkedHashMap<String,String>();
	static{
		monitoringMap.put("1", "交易队列");
		monitoringMap.put("2", "推送结果");
		monitoringMap.put("3", "交易结果");
	}
	//选择条件1
	public final static Map<String,String> selectMap = new LinkedHashMap<String,String>();
	
	{
		selectMap.put("0", "手机号");
		selectMap.put("1", "用户名");
		selectMap.put("2", "真实姓名");
		selectMap.put("3", "身份证号码");
		selectMap.put("4", "银行卡号");
	}
	
	public final static String PHONENUM = "phoneUum";
	public final static String LOGINNAME = "loginName";
	public final static String USERID = "userId";
	public final static String NICKNAME = "nickName";
	public final static String CARDNUM = "cardNum";
	public final static String BANKNO = "bankNo";
	// 选择条件2
	public final static Map<String,String> selMap = new LinkedHashMap<String,String>();
	
	{
		selMap.put("1", "时间查询");
		selMap.put("0", "期号查询");
	}
	//用户变更明细
	public final static Map<String, String> changeTypeMap = new LinkedHashMap<String, String>();
	{	
		//变更类型
		changeTypeMap.put("mobile_update", "变更手机号");
		changeTypeMap.put("pwd_update", "修改密码");
		changeTypeMap.put("bank_update", "变更银行卡");
		changeTypeMap.put("loginOut", "用户登出");
		changeTypeMap.put("user_realName", "用户实名");
		changeTypeMap.put("winstant_login", "用户登录");
		changeTypeMap.put("user_register", "用户注册");
		changeTypeMap.put("pwd_find", "密码找回");
	}
	
	//用户日志变更途径
	public final static Map<String, String> userTypeMap = new LinkedHashMap<String, String>();
	{	//变更途径
		userTypeMap.put("10", "手机客户端");
		userTypeMap.put("20", "即开票");	
		userTypeMap.put("30", "oss");
	}
	
	
	/**
	 * 根据选择的单选  获得用户编码
	 * @param confirmSelect
	 * @param confirmMsg
	 * @return
	 * @throws BizException
	 * 2015年12月4日 by zhangyi
	 */
	protected String getUserId(String confirmSelect,String confirmMsg) throws BizException {
		/*confirmMsg = ObjectUtil.formatString(confirmMsg);// 目的是找到userId
		if(confirmMsg == null){
			return null;
		}
		String userId = null;
		String phoneNum = null;
		String loginName = null;
		if(confirmSelect.equals("0")){
			phoneNum = confirmMsg;
		}else if(confirmSelect.equals("1")){
			loginName = confirmMsg;
		} else{
			userId = confirmMsg;
		}
		if(userId == null){
			List<UserInfoVO> listRr = dubboUserService.queryUserInfo(loginName, null, phoneNum, null, null, 1, 1);
			if(listRr == null || listRr.size() < 1){
				return userId;
			}
			userId = listRr.get(0).getUserId();
		}
		return userId;*/
		return "";
	}
	/**
	 * 根据选择的单选  设置map对应的值
	 * @param confirmSelect
	 * @param confirmMsg
	 */
	public static Map<String,String> getMapKV(String confirmSelect,String confirmMsg){
		
		Map<String,String> map = new HashMap<String,String>();
		confirmMsg = ObjectUtil.formatString(confirmMsg);// 目的是找到userId
		if(confirmMsg == null || confirmSelect == null){
			return map;
		}
		String userId = null;
		String phoneNum = null;
		String loginName = null;
		String nickName = null;
		String cardNum = null;
		String bankNo = null;
		if(confirmSelect.equals("0")){
			phoneNum = confirmMsg;
		}else if(confirmSelect.equals("1")){
			loginName = confirmMsg;
		}else if(confirmSelect.equals("2")){
			nickName = confirmMsg;
		}else if(confirmSelect.equals("3")){
			cardNum = confirmMsg;
		}else if(confirmSelect.equals("4")){
			bankNo = confirmMsg;
		}else{
			userId = confirmMsg;
		}
		map.put(USERID, userId);
		map.put(PHONENUM, phoneNum);
		map.put(LOGINNAME, loginName);
		map.put(NICKNAME, nickName);
		map.put(CARDNUM, cardNum);
		map.put(BANKNO, bankNo);
		return map;
	}
	protected void getIssueSel(String confirmSel,String start,String end,Map<String,Object> map){
		confirmSel = ObjectUtil.formatString(confirmSel);
		start = ObjectUtil.formatString(start);
		end = ObjectUtil.formatString(end);
		
		if(confirmSel.equals("0")){//期号查询
			map.put("startIssue", start);
			map.put("endIssue", end);
		}else{//时间查询
			map.put("startTime", start);
			map.put("endTime", end);
		}
		
	}

	/**
	 *
	 * 根据用户id获取分别ID
	 * @param userId
	 * @return
	 * 2015年9月16日 by ziqiang.zhang
	 */
	public int getTableId(String userId){

		return Integer.parseInt(TableNoAllocatorFactory.getAllocator(TableNoAllocator.USER_INFO.getCode()).getTableNo(userId));
	}

	/** 分表选择器 */
	public static enum TableNoAllocator {
		USER_INFO("t_user_info"), CASH_BILL("t_cash_bill");
		private String code;

		private TableNoAllocator(String code) {
			this.code = code;
		}

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}
	}
}
